package o;

import android.annotation.SuppressLint;
import android.graphics.ColorSpace;
import android.graphics.ColorSpace.Named;
import android.graphics.ImageDecoder;
import android.graphics.ImageDecoder.DecodeException;
import android.graphics.ImageDecoder.ImageInfo;
import android.graphics.ImageDecoder.OnHeaderDecodedListener;
import android.graphics.ImageDecoder.OnPartialImageListener;
import android.graphics.ImageDecoder.Source;
import android.os.Build.VERSION;
import android.util.Log;
import android.util.Size;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
import com.bumptech.glide.load.DecodeFormat;
import com.bumptech.glide.load.resource.bitmap.Downsampler;
import java.io.IOException;

@RequiresApi(api = 28)
public abstract class wd<T> implements se<Source, T> {
    final wx ˏ = wx.ˊ();

    protected abstract tx<T> ॱ(Source source, int i, int i2, OnHeaderDecodedListener onHeaderDecodedListener) throws IOException;

    @Nullable
    public /* synthetic */ tx ˎ(@NonNull Object obj, int i, int i2, @NonNull sc scVar) throws IOException {
        return ॱ((Source) obj, i, i2, scVar);
    }

    public final boolean ˊ(@NonNull Source source, @NonNull sc scVar) {
        return true;
    }

    @Nullable
    public final tx<T> ॱ(@NonNull Source source, int i, int i2, @NonNull sc scVar) throws IOException {
        final DecodeFormat decodeFormat = (DecodeFormat) scVar.ॱ(Downsampler.DECODE_FORMAT);
        final wu wuVar = (wu) scVar.ॱ(wu.ʼ);
        final boolean z = scVar.ॱ(Downsampler.ALLOW_HARDWARE_CONFIG) != null && ((Boolean) scVar.ॱ(Downsampler.ALLOW_HARDWARE_CONFIG)).booleanValue();
        final sf sfVar = (sf) scVar.ॱ(Downsampler.PREFERRED_COLOR_SPACE);
        final int i3 = i;
        final int i4 = i2;
        return ॱ(source, i, i2, new OnHeaderDecodedListener(this) {
            final /* synthetic */ wd ʻ;

            @SuppressLint({"Override"})
            public void onHeaderDecoded(ImageDecoder imageDecoder, ImageInfo imageInfo, Source source) {
                if (this.ʻ.ˏ.ˋ(i3, i4, z, false)) {
                    imageDecoder.setAllocator(3);
                } else {
                    imageDecoder.setAllocator(1);
                }
                if (decodeFormat == DecodeFormat.PREFER_RGB_565) {
                    imageDecoder.setMemorySizePolicy(0);
                }
                imageDecoder.setOnPartialImageListener(new OnPartialImageListener(this) {
                    final /* synthetic */ AnonymousClass4 ˊ;

                    {
                        this.ˊ = r1;
                    }

                    public boolean onPartialImage(@NonNull DecodeException decodeException) {
                        return false;
                    }
                });
                Size size = imageInfo.getSize();
                int i = i3;
                if (i3 == Integer.MIN_VALUE) {
                    i = size.getWidth();
                }
                int i2 = i4;
                if (i4 == Integer.MIN_VALUE) {
                    i2 = size.getHeight();
                }
                float ˎ = wuVar.ˎ(size.getWidth(), size.getHeight(), i, i2);
                i2 = Math.round(((float) size.getWidth()) * ˎ);
                int round = Math.round(((float) size.getHeight()) * ˎ);
                if (Log.isLoggable("ImageDecoder", 2)) {
                    Log.v("ImageDecoder", "Resizing from [" + size.getWidth() + "x" + size.getHeight() + "] to [" + i2 + "x" + round + "] scaleFactor: " + ˎ);
                }
                imageDecoder.setTargetSize(i2, round);
                if (VERSION.SDK_INT >= 28) {
                    if (sfVar == sf.DISPLAY_P3 && imageInfo.getColorSpace() != null && imageInfo.getColorSpace().isWideGamut()) {
                        i = 1;
                    } else {
                        boolean z = false;
                    }
                    imageDecoder.setTargetColorSpace(ColorSpace.get(i != 0 ? Named.DISPLAY_P3 : Named.SRGB));
                } else if (VERSION.SDK_INT >= 26) {
                    imageDecoder.setTargetColorSpace(ColorSpace.get(Named.SRGB));
                }
            }
        });
    }
}
